let age: number = 22;
console.log(age);

let username: string = "张三";
console.log(username);

let married: boolean = false;
console.log(married);

let password: null = null;
console.log(password);

let email: undefined = undefined;
console.log(email);

// node 16.0环境可以使用, 高版本不能使用
// const phone: symbol = Symbol("88");
// console.log(phone);

let scores: number[] = [12, 34, 31, 53, 67];
console.log(scores);
let arr: Array<string> = ["侯帅康", "田振齐"];
console.log(arr);

// let arr2: (number | string)[] = [1, 2, 3, 4, 5, 6, 7, "侯帅康", "田振齐"];
let arr3: Array<string | number> = [1, 2, 3, 4, 5, 6, 7, "侯帅康", "田振齐"];
console.log(arr3);

// number或者null值
let arr4: number | null = null;

type arrNum = (number | string)[];
let arr5: arrNum = [1, 2, 3, 4, 5, 6, 7, "侯帅康", "田振齐"];

function show(x: string, y: number): string {
  console.log("show函数");
  return x + y;
}
let x: string = show("33", 4);
console.log(x);

// 可选参数
function fun1(x: number, y?: number, z?: number) {
  console.log(x, y, z);
}
fun1(2, 3, 4);

// 接口: 所有属性不需要初始值
interface Person {
  name: string;
  age: number;
  say(): void;
}

// 类属性必须有初始值
class PersonModel {
  name: string = "";
  age: number = 0;
  say() {
    console.log("8");
  }
  constructor(name: string, age: number) {
    this.name = name;
    this.age = age;
  }
}
let p0: PersonModel = new PersonModel("李四", 20);
console.log(p0);

// 对象
let p: {
  name: string;
  age: number;
  study(): number;
} = {
  name: "张三",
  age: 20,
  study() {
    console.log(8);
    return 4;
  },
};
// 接口
let p2: Person = {
  name: "张三",
  age: 20,
  say() {
    console.log("说话");
  },
};
// 类
let p3: PersonModel = {
  name: "张三",
  age: 20,
  say() {
    console.log("说话");
  },
};
console.log(p);
console.log(p2);
console.log(p3);
